!function(window,document,$){
    var ip='192.168.0.149';
    var init=function(){
        initEvent();
        getData();
    };
    var initEvent=function(){
        $('.tops').click(gtOnclick);
        $('.zonghe').click(zongHeCLK);
        $('.renqi').click(renQiClk);
        $('.goodp').click(haoPingClk);
    };



    window.onscroll = function () {
        var $gt = $('.tops');
        var osTop = document.documentElement.scrollTop;
        if (osTop > 500) {
            $gt.css({
                'display':'block'
            })
        } else {
            $gt.css({
                "display":"none"
            })
        }
    };

    var zongHeCLK=function(){
        getData('http://'+ip+'/tp5/public/index.php/index/teachers?pageCurrent=1&pageSize=12');
        $(this).addClass('active');
        $(this).prevAll().removeClass('active');
        $(this).nextAll().removeClass('active');
    };

    var renQiClk=function(){
        getData('http://'+ip+'/tp5/public/index.php/index/teachers?pageCurrent=1&pageSize=12')
        $(this).addClass('active');
        $(this).prevAll().removeClass('active');
        $(this).nextAll().removeClass('active');
    };

    var haoPingClk=function(){
        getData('http://'+ip+'/tp5/public/index.php/index/teachers?pageCurrent=1&pageSize=12')
        $(this).addClass('active');
        $(this).prevAll().removeClass('active');
        $(this).nextAll().removeClass('active');
    };

      var gtOnclick=function(){
        timer = setInterval(function () {
            var osTop = document.documentElement.scrollTop;
            var speed = Math.floor(-osTop / 6);
            document.documentElement.scrollTop = document.body.scrollTop = osTop + speed;
            if (osTop == 0) {
                clearInterval(timer);
            }
        }, 10)
    };

    $('.menu').find('li').on('click',function(){
        $(this).addClass('active');
        $(this).prevAll().removeClass('active');
        $(this).nextAll().removeClass('active');
    })

    function getData(url) {
        var $loading=$('.loadings');
        $loading.css({
            'display':'block'
        })
        console.log(url);
        urls=url?url:'http://'+ip+'/tp5/public/index.php/index/teachers?pageCurrent=1&pageSize=12';
        var ajsx;
        if (window.XMLHttpRequest) {
            ajax = new XMLHttpRequest();
        } else {
            ajax = new ActiveXObject(Microsoft.XMLHttp);
        }
        ajax.open('get', urls);
        ajax.send();
        ajax.onreadystatechange = function () {
            if (ajax.readyState == 4 && ajax.status == 200) {
                // console.log(JSON.parse(ajax.responseText));
                render(JSON.parse(ajax.responseText).data.list);
                $loading.css({
                    'display':'none'
                })
            }
        }
        // $.ajax({
        //     url: 'http://localhost/api.php/yuzhiyuan/teachers?transform=1',
        //     type: 'get',
        //     async: false,
        //     success: function (res) {
        //         console.log(1)
        //         render(res.teachers);
        //         console.log(res);

        //     }
        // })
    };

    function render(list) {
        var $content = $('.render_ul');
        console.log(list);
        var listarr = [];
        $.each(list, function (i, o) {
            listarr.push('<li>',
                '<div class="content_item">',
                '<div class="content_item_top">',
                '<img src="', o.img, '" alt="" class="content_item_img">',
                '<p class="teacher_name">', o.name, '</p>',
                '<div class="content_star">',
                '<i class="dis_ib star_wp">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<img src="http://ilty.gitee.io/img/YuZhiYuan/shoye/nostar.png" alt="" class="star">',
                '<p class="blackstar"></p>',
                '</i>',
                '<span class="nub">', o.veal, '分</span>',
                '</div>',
                '<div class="clear">',
                '<span class="fl content_meici_font">开课：', o.classes, '</span>',
                '<span class="fr content_meici_font">招生：', o.comment, '</span>',
                '</div>',
                '</div>',
                '<div class="content_item_bt">',
                '<p class="xueli">', o.desc, '</p>',
                '<p class="btn">',
                '<a href="javascript:;">Ta的主页</a>',
                '</p>',
                '</div>',
                '</div>',
                '</li>')
        })
        $content.html(listarr.join(''))
        var $blackstar = $('.blackstar');
        $.each($blackstar, function (i, o) {
                var blWid = list[i].veal / 5 * 18 * 5;
                o.style.width=blWid+"px";
        })
    };

    init();
}(window,document,jQuery,undefined)